/**
 * JAVACC DEMO 1.0
 */
package com.apache.portal.contorller.uct;

import com.apache.api.vo.ResultEntity;
import com.apache.api.vo.ResultMsg;
import com.apache.cache.util.Validator;
import com.apache.client.UctCoreClient;
import com.apache.client.common.SmsUtil;
import com.apache.exception.BusinessException;
import com.apache.license.validator.TeaUtil;
import com.apache.passport.common.PassportHelper;
import com.apache.passport.entity.Token;
import com.apache.portal.common.PortalPlugin;
import com.apache.portal.common.SendService;
import com.apache.portal.common.annotion.BeanFactory;
import com.apache.portal.common.connector.impl.AdapterFactory;
import com.apache.portal.common.oscache.BaseOsCache;
import com.apache.portal.common.oscache.OsCacheOtherManager;
import com.apache.portal.common.restfull.RequestMapping;
import com.apache.portal.common.restfull.ResultFullAnntation;
import com.apache.portal.common.restfull.SupperAction;
import com.apache.portal.common.util.HttpRequest;
import com.apache.portal.common.util.PortalPubFactory;
import com.apache.portal.common.util.PortalUtil;
import com.apache.portal.common.util.Trans2PinYin;
import com.apache.rpc.entity.InterfaceRegister;
import com.apache.tools.ConfigUtil;
import com.apache.tools.MD5Utils;
import com.apache.tools.StrUtil;
import com.apache.uct.common.LoginUser;
import com.apache.uct.common.PBOSSOTools;
import com.apache.uct.common.ToolsUtil;
import com.apache.uct.common.entity.User;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.*;

/**
 * description:  用户中心对接Action
 *
 * @author dyhou 创建时间：2016-5-17
 */
@SuppressWarnings("serial")
@ResultFullAnntation(name = "uctAction", urlPatterns = { "/res/uct/*", "/res/uct/admin/*" })
public class UctAction extends SupperAction {//res/uct/dymicSql

    private PortalPlugin plugin;

    private PortalPlugin netPlugin;

    public void init() {
        plugin = (PortalPlugin) BeanFactory.getInstance().getBeans("uct");
        netPlugin = (PortalPlugin) BeanFactory.getInstance().getBeans("net");
    }

    protected void doInvoke(HttpServletRequest request, HttpServletResponse response,
            String methodType) throws Exception {
        Method method = doInvoke(this.getClass(), request, response, methodType, "");
        if (null != method) {
            Object obj = method.invoke(this, request, response);
            if (!ToolsUtil.isEmpty(obj)) {
                JSONObject array = JSONObject.fromObject(obj);
                this.outputJson(array.toString(), response, request.getParameter("callback"));
            }
        } else {
            gotoErrorPage(request, response, "请求方式有误或请求地址未定义");
        }
    }

    /**
     * description:  获取用户登录信息
     * @param request
     * @param response
     */
    @RequestMapping(value = "login", method = "get")
    protected Object findLoginUser(HttpServletRequest request, HttpServletResponse response) {
        Map<String, String> map = new HashMap<String, String>();
        LoginUser loginUser = PortalUtil.getInstance().getLoginUser(request);
        map.put("flag", "F");
        if (!ToolsUtil.isEmpty(loginUser)) {
            map.put("flag", "T");
            map.put("userCname", loginUser.getUserCname());
            map.put("email", loginUser.getEmail());
            map.put("mobile", loginUser.getMobile());
            map.put("userId", loginUser.getUserId());
            map.put("userEname", loginUser.getUserEname());
            map.put("sysFlag", loginUser.getSysFlag());
            map.put("userType",loginUser.getUserType());
        }
        return map;
    }

    /**
     * 修改是否启用 登录验证码校验
     * @param request state:T/F
     * @param response
     * @return
     */
    @RequestMapping(value = "modifyPropRandCode", method = "post")
    protected ResultMsg modifyPropRandCode(HttpServletRequest request, HttpServletResponse response) {
        ResultMsg msg = new ResultMsg("F","操作失败");
        try {
            Map<String, String> params = this.getParameterMap(request);
            String state = StrUtil.doNull(params.get("state"),"T");
            if (StrUtil.isNotNull(state)){
                String fileNamePath = ToolsUtil.getClassLoaderPath()+"config/config.properties";
                Properties properties = ToolsUtil.getInstance().getProperties(fileNamePath);
//                System.out.println(ToolsUtil.getClassLoaderPath()+fileName);
                OutputStream fos = new FileOutputStream(fileNamePath);
                properties.setProperty("if_randCode",state);
                properties.store(fos,"");
                fos.close();
                msg = new ResultMsg("T","操作成功");
                log.info("config.properties->if_randCode=["+state+"]"+msg.toString());
            }
        } catch (IOException e) {
            msg = new ResultMsg("F","操作失败");
            e.printStackTrace();
        }
        return msg;
    }

    /**
     * 用户登录
     */
    @RequestMapping(value = "login", method = "post")
    protected ResultMsg login(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        ResultMsg msg = null;
//        String cookieValue = PassportHelper.getInstance().getCurrCookie(request);
//        if (ToolsUtil.isNull(cookieValue)) {
            Map<String, String> params = this.getParameterMap(request);
            String if_randCode = ToolsUtil.getInstance().getLocalByKey("config.properties","if_randCode");
            if ("F".equals(if_randCode)) {
                msg = null;
            } else {
                msg = checkRandCode(request, params);
            }

            if (null == msg) {
                params.put("doCode", "U0001");
                msg = (ResultMsg) plugin.doInvoke(request, response,
                        params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
                if ("T".equals(msg.getFlag())) {
                    JSONObject jb = JSONObject.fromObject(msg.getMsg());
                    Map<String, Object> map = (Map) jb;
                    LoginUser loginUser = PBOSSOTools
                            .getLoginUserFromUserCenter(String.valueOf(map.get("userEname")),
                                    String.valueOf(map.get("tokenId")));
                    if (loginUser != null) {
                        map.put("sysFlag", loginUser.getSysFlag());
                        map.put("auditStatus", loginUser.getUser().getAuditStatus());
                    }
                    msg.setMsg(JSONObject.fromObject(map).toString());
                    request.getSession().setAttribute("loginUser", loginUser);
                }
            }
        /**} else {
            setLoginUser(request);
            LoginUser loginUser = (LoginUser) request.getSession().getAttribute("loginUser");
            String userType = "customer";
            String customerType = "person";
            Map<String, String> umap = new HashMap<String, String>();
            Token token = new Token();
            if (null != loginUser) {
                umap.put("email", loginUser.getEmail());
                umap.put("mobile", loginUser.getMobile());
                umap.put("userEname", loginUser.getUserEname());
                umap.put("userCname", loginUser.getUserCname());
                umap.put("auditStatus", loginUser.getUser().getAuditStatus());
                userType = StrUtil.doNull(loginUser.getUserType(), userType);
                customerType = StrUtil.doNull(loginUser.getUser().getCustomerType(), customerType);
            }
            umap.put("userType", userType);
            umap.put("customerType", customerType);
            umap.put("sysFlag", loginUser.getSysFlag());
            token.setUserType(userType);
            token.setCustomerType(customerType);
            msg = new ResultMsg("T", JSONObject.fromObject(umap).toString());
        }**/
        log.info("登录结果："+msg.toString());
        return msg;
    }

    /**
     *
     * aie中航用户登录
     * 不需要验证码校验
     */
    @RequestMapping(value = "aieLogin", method = "post")
    protected ResultMsg aieLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
        ResultMsg msg = null;
        String cookieValue = PassportHelper.getInstance().getCurrCookie(request);
        if (ToolsUtil.isNull(cookieValue)) {
            Map<String, String> params = this.getParameterMap(request);
            params.put("doCode", "U0001");
            msg = (ResultMsg) plugin.doInvoke(request, response, params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
            if ("T".equals(msg.getFlag())) {
                JSONObject jb = JSONObject.fromObject(msg.getMsg());
                Map<String, Object> map = (Map) jb;
                LoginUser loginUser = PBOSSOTools
                        .getLoginUserFromUserCenter(String.valueOf(map.get("userEname")),
                                String.valueOf(map.get("tokenId")));
                if (loginUser != null) {
                    map.put("sysFlag", loginUser.getSysFlag());
                    map.put("auditStatus", loginUser.getUser().getAuditStatus());
                }
                msg.setMsg(JSONObject.fromObject(map).toString());
                request.getSession().setAttribute("loginUser", loginUser);
            }
        }else {
            setLoginUser(request);
            LoginUser loginUser = (LoginUser) request.getSession().getAttribute("loginUser");
            String userType = "customer";
            Map<String, String> umap = new HashMap<String, String>();
            Token token = new Token();
            if (null != loginUser) {
                umap.put("email", loginUser.getEmail());
                umap.put("mobile", loginUser.getMobile());
                umap.put("userEname", loginUser.getUserEname());
                umap.put("userCname", loginUser.getUserCname());
                userType = StrUtil.doNull(loginUser.getUserType(), userType);
            }
            umap.put("userType", userType);
            umap.put("sysFlag", loginUser.getSysFlag());
            token.setUserType(userType);
            msg = new ResultMsg("T", JSONObject.fromObject(umap).toString());
        }
        return msg;
    }
    /**
     * 第三方登录方法：qq快捷登录
     *
     * @param request
     * @param response
     * @return
     */
    @SuppressWarnings({ "unchecked", "unused" })
    @RequestMapping(value = "qqLogin", method = "get")
    protected void qqLogin(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        ResultMsg msg = null;
        String cookieValue = PassportHelper.getInstance().getCurrCookie(request);
        String code = request.getParameter("code");
        String appid = ToolsUtil.getInstance().getValueByKey("51094_appId");
        String token = ToolsUtil.getInstance().getValueByKey("51094_token");
        String url = HttpRequest.sendPost("http://open.51094.com/user/auth.html",
                "type=get_user_info&code=" + code + "&appid=" + appid + "&token=" + token + "");
        //this.outputJson(url, response);
        JSONObject jsonObj = JSONObject.fromObject(url);
        String name = (String) jsonObj.get("name");
        String img = (String) jsonObj.get("img");
        int sex = (Integer) jsonObj.get("sex");
        String uniq = (String) jsonObj.get("uniq");
        String from = (String) jsonObj.get("from");
        String userEname = Trans2PinYin.trans2PinYin(name);

        Map<String, String> param = new HashMap<String, String>();
        param.put("doCode", "U0007");
        param.put("userId", uniq);//QQ登录完成之后，uniq作为账号
        //查询是否登录过
        ResultEntity obj = UctCoreClient.getUserByProperty("userId", uniq);
        User user = null;
        if (null == obj.getEntity()) {
            //未登陆过，先添加数据
            param.clear();
            param.put("uctUser.userId", uniq);
            param.put("uctUser.userEname", userEname);
            //			param.put("pageName", "qq-reg");
            //			param.put("formName", "addForm");
            //			param.put("uctUserSys.splitAttr", "sysId");
            //			param.put("ifBatch", "T");
            String pass = MD5Utils.MD5(MD5Utils.MD5(userEname) + "iussoft");
            param.put("uctUser.userPass", pass);
            param.put("uctUser.userCname", name);
            param.put("uctUser.regSource", from);
            param.put("uctUser.userStatus", "1");
            param.put("uctUser.sysEname", "web");
            param.put("uctUser.userLevel", "0");
            param.put("uctUser.userType", "member");
            param.put("uctUser.auditStatus", "0");
            Map<String, String> params = getParameterMap(request);
            params.putAll(param);
            params.put("doCode", "dymicSql");
            params.put("pageName", "qq-reg");
            params.put("formName", "addForm");
            params.put("resultType", "processSql");
            Map<String, Object> result = new HashMap<String, Object>();
            params = AdapterFactory.getInstance()
                    .getReqParamForBefor("setReqParam,createInfo", params, request, response);//前拦截
            String execptionMsg = String.valueOf(params.get("execptionMsg"));
            ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                    params);//PortalPubFactory.getInstance().getPlugin("net")
            //	.doInvoke(request, response, params);
            result.put("flag", String.valueOf(entity.getResult()));
            result.put("msg", String.valueOf(entity.getMessage()));
            user = new User();
            user.setUserEname(userEname);
            user.setUserPass(pass);
        } else {
            user = (User) obj.getEntity();
            //如果QQ昵称改变
            if (!user.getUserEname().equals(userEname)) {
                param.clear();
                param.put("uctUser.w_userId", uniq);
                param.put("uctUser.userEname", userEname);
                //			param.put("pageName", "qq-reg");
                //			param.put("formName", "addForm");
                //			param.put("uctUserSys.splitAttr", "sysId");
                //			param.put("ifBatch", "T");
                String pass = MD5Utils.MD5(MD5Utils.MD5(userEname) + "iussoft");
                param.put("uctUser.userPass", pass);
                param.put("uctUser.userCname", name);
                param.put("uctUser.regSource", from);
                param.put("uctUser.userStatus", "1");
                param.put("uctUser.sysEname", "web");
                param.put("uctUser.userLevel", "0");
                param.put("uctUser.userType", "member");
                param.put("uctUser.auditStatus", "0");
                Map<String, String> params = getParameterMap(request);
                params.putAll(param);
                params.put("doCode", "dymicSql");
                params.put("pageName", "qq-reg");
                params.put("formName", "editForm");
                params.put("resultType", "processSql");
                Map<String, Object> result = new HashMap<String, Object>();
                params = AdapterFactory.getInstance()
                        .getReqParamForBefor("setReqParam,createInfo", params, request,
                                response);//前拦截
                String execptionMsg = String.valueOf(params.get("execptionMsg"));
                ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                        params);//PortalPubFactory.getInstance().getPlugin("net")
                //.doInvoke(request, response, params);
                result.put("flag", String.valueOf(entity.getResult()));
                result.put("msg", String.valueOf(entity.getMessage()));
                user = new User();
                user.setUserEname(userEname);
                user.setUserPass(pass);
            }
        }

        //登录
        param.clear();
        param.put("username", user.getUserEname());
        param.put("password", user.getUserPass());
        param.put("doCode", "U0001");
        param.put("sysPass", ConfigUtil.getInstance().interfacePass());
        msg = (ResultMsg) plugin.doInvoke(request, response,
                param);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, param);
        String f = msg.getFlag();
        if ("T".equalsIgnoreCase(msg.getFlag())) {///sendPage/sale/login-jump
            response.sendRedirect("/sendPage/sale/login-jump");
            //request.getRequestDispatcher("/sendPage/sale/login-jump").forward(request, response);
        } else {
            request.setAttribute("errors", "登录失败");
            request.getRequestDispatcher("/doSendPage?toPage=error").forward(request, response);
        }
    }

    /**
     * 为其它客户端（如C/S)提供的登录入口
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "loginClient", method = "post")
    protected ResultMsg loginClient(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        ResultMsg msg = null;
        Map<String, String> params = this.getParameterMap(request);
        //		msg = checkRandCode(request, params);//不需要验证码
        if (null == msg) {
            params.put("doCode", "U0001");
            msg = (ResultMsg) plugin.doInvoke(request, response,
                    params);// PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        }
        return msg;
    }

    @RequestMapping(value = "userInfo", method = "post")
    protected ResultMsg userInfo(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        ResultMsg msg = new ResultMsg("F", "查询失败");
        Map<String, String> params = this.getParameterMap(request);
        params.put("doCode", "U0007");
        params.put("userEname", params.get("username"));
        Object obj = plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        if (null != obj) {
            User user = (User) obj;
            msg = new ResultMsg("T", JSONObject.fromObject(user).toString());
        }
        return msg;
    }

    /**
     * description:  邮箱链接验证，页面跳转（白名单）
     */
    @RequestMapping(value = "checkEmail", method = "get")
    protected void checkEmailForPassword(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Map<String, String> params = this.getParameterMap(request);
        if ("U0006".equals(params.get("doCode"))) {
            setUserPwd(request, response, params);
        } else {
            gotoErrorPage(request, response, "请求的Action地址未定义");
        }
    }

    /**
     * description:  登录成功后跳转页面（白名单）
     * 使用页面：login_frame.jsp/login_index.jsp
     */
    @RequestMapping(value = "toIndex", method = "get")
    protected void toIndex(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        gotoIndex(request, response);
    }

    /**
     * description:  用户退出操作（白名单）
     * 使用页面：editUser.jsp
     */
    @RequestMapping(value = "logout", method = "post")
    protected ResultMsg logout(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        params.put("doCode", "U0000");
        ResultMsg msg = (ResultMsg) plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        return msg;
    }

    /**
     * description:  用户注册操作（白名单）
     * 使用页面：userReg.jsp
     */
    @RequestMapping(value = "regUser", method = "post")
    protected ResultMsg regUser(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        String mail_start = ToolsUtil.getInstance().getValueByKey("mail_start");
        ResultMsg msg = null;
        if ("T".equals(mail_start)) {//开启发邮件才校验
            msg = checkEmailCode(request, params);
            if ("T".equals(msg.getFlag())) {
                params.put("doCode", "U0009");
                msg = (ResultMsg) plugin.doInvoke(request, response,
                        params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
                //清楚同一个浏览器 上一次的注册信息
                if (msg.getFlag().equals("T")) {
                    request.getSession().removeAttribute("reg_username");//添加注册邮箱(用户名)与验证码绑定
                    request.getSession().removeAttribute("mailCode");
                    request.getSession().removeAttribute("sendTime");
                }
            }
        } else {//未开启发邮件，直接注册
            msg = checkRandCode(request, params);
            if (null == msg) {
                params.put("doCode", "U0002");
                msg = (ResultMsg) plugin.doInvoke(request, response,
                        params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
            }
        }
        return msg;
    }

    /**
     * 根据需求修改任何表的字段
     */
    @RequestMapping(value = "dymicSql", method = "post")
    protected Object dymicSql(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "dymicSql");
        params.put("resultType", "processSql");
        Map<String, Object> result = new HashMap<String, Object>();
        params = AdapterFactory.getInstance()
                .getReqParamForBefor("setReqParam", params, request, response);//前拦截
        String execptionMsg = String.valueOf(params.get("execptionMsg"));
        if (StrUtil.isNotNull(execptionMsg)) {
            ResultMsg msg = new ResultMsg("F", execptionMsg);
            return msg;
        }
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        result.put("flag", String.valueOf(entity.getResult()));
        result.put("msg", String.valueOf(entity.getMessage()));
        result.put("ids", entity.getEntity());
        return result;
    }

    /**
     * description:  用户注册操作（白名单）
     * 使用页面：userReg.jsp
     */
    @RequestMapping(value = "regDymic", method = "post")
    protected Object regDymic(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "dymicSql");
        params.put("resultType", "processSql");
        if (StrUtil.isNotNull(params.get("uctUser.userEname"))) {
            params.put("loginUser_userEname", params.get("uctUser.userEname"));//确保其他表中没有该字段
        }
        Map<String, Object> result = new HashMap<String, Object>();
        /***/
        String ifChangeMobile = request.getParameter("ifChangeMobile");
        if ((Validator.isNull(ifChangeMobile)) || (ifChangeMobile.equals("1"))) {
            String randCheck = ToolsUtil.getInstance().getValueByKey("randCheck");
            if (randCheck.equals("Y")) {
                ResultMsg msg = checkSmsCode(request, params);
                if ((msg != null) && (msg.getFlag().equals("F"))) {
                    result.put("flag", msg.getFlag());
                    result.put("msg", msg.getMsg());
                    result.put("ids", null);
                    return result;
                }
            } else {
                ResultMsg msg = checkRandCode(request, params);
                if ((msg != null) && (msg.getFlag().equals("F"))) {
                    result.put("flag", msg.getFlag());
                    result.put("msg", msg.getMsg());
                    result.put("ids", null);
                    return result;
                }
            }
        }
        /***/
        params = AdapterFactory.getInstance()
                .getReqParamForBefor("setReqParam,createInfo", params, request, response);//前拦截
        String execptionMsg = String.valueOf(params.get("execptionMsg"));
        if (StrUtil.isNotNull(execptionMsg)) {
            ResultMsg msg = new ResultMsg("F", execptionMsg);
            return msg;
        }
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("net")
        //.doInvoke(request, response, params);
        result.put("flag", String.valueOf(entity.getResult()));
        result.put("msg", String.valueOf(entity.getMessage()));
        result.put("ids", entity.getEntity());
        return result;
    }

    /**
     * description:  找回密码（白名单）
     * 使用页面：resPassword.jsp
     */
    @RequestMapping(value = "findPwd", method = "post")
    protected ResultMsg findPwd(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        ResultMsg msg = checkRandCode(request, params);
        if (null == msg) {
            params.put("doCode", "U0004");
            msg = (ResultMsg) plugin.doInvoke(request, response,
                    params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        }
        return msg;
    }

    /**
     * description:  修改密码(通过邮箱找密码链接过来的修改密码）
     * 使用页面：setPassword.jsp
     */
    @RequestMapping(value = "editPwd", method = "post")
    protected ResultMsg editPwd(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        ResultMsg msg = checkRandCode(request, params);
        if (null == msg) {
            params.put("doCode", "U0005");
            msg = (ResultMsg) plugin.doInvoke(request, response,
                    params);// PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        }
        return msg;
    }

    /**
     * description:  修改用户信息操作
     * 使用页面：editUser.jsp
     */
    @RequestMapping(value = "editUser", method = "post")
    protected ResultMsg editUser(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        LoginUser loginUser = PBOSSOTools.getLoginUser(request);
        if (ToolsUtil.isEmpty(loginUser)) {
            this.gotoLogin(request, response, "");
            return null;
        }
        params.put("doCode", "U0003");
        ResultMsg msg = (ResultMsg) plugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        return msg;
    }

    /**
     * 发送邮件
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "sendCode", method = "post")
    protected ResultMsg sendCode(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        ResultMsg msg = new ResultMsg("F", "验证码发送失败");
        Map<String, String> params = this.getParameterMap(request);
        long sendTime = System.currentTimeMillis();
        String msgType = StrUtil.doNull(request.getParameter("sendType"), "mail");
        String mail_start = ToolsUtil.getInstance().getValueByKey("mail_start");
        if (!"T".equals(mail_start)) {
            msg = new ResultMsg("F", "服务端已停用发送邮件通知业务");
            return msg;
        }
        if ("mail".equalsIgnoreCase(msgType)) {
            String times = StrUtil
                    .doNull(String.valueOf(request.getSession().getAttribute("sendTime")), "0");
            long sendTimeUp = Long.valueOf(times);
            long count = 1 * 60 * 1000;
            //			if (sendTime - sendTimeUp > count) {
            String codeNumber = PortalPubFactory.getRandomNumber(6);
            Map<String, String> sendMap = new HashMap<String, String>();
            String userEmail = params.get("email");
            log.info("正在给[" + userEmail + "]发送邮箱验证码...");
            sendMap.put("userEmail", userEmail);
            sendMap.put("content", codeNumber);
            sendMap.put("title", ToolsUtil.getInstance().getValueByKey("mail.title.code.number"));
            sendMap.put("tempName", "mailCodeNumber.inc");//指定使用的模板
            sendMap.put("emailPwd", ToolsUtil.getInstance().getValueByKey("mail_pwd"));
            sendMap.put("host", ToolsUtil.getInstance().getValueByKey("mail_host"));
            sendMap.put("from", ToolsUtil.getInstance().getValueByKey("mail_user"));
            sendMap.put("protocol", ToolsUtil.getInstance().getValueByKey("mail.protocol"));
            sendMap.put("platformName",
                    ToolsUtil.getInstance().getValueByKey("mail.platform.name"));
            log.info("发送内容：" + sendMap);
            SendService service = (SendService) BeanFactory.getInstance().getBeans("sendEmail");
            //PortalPubFactory.getInstance().setSends("findPwdEmail", new SendEmailServiceImpl());
            //发送邮件
            boolean mark = service.sendMessage(
                    sendMap);//PortalPubFactory.getInstance().getSends("findPwdEmail").sendMessage(sendMap);
            log.info("发送结果：" + mark);
            if (mark) {
                msg = new ResultMsg("T", "验证码发送成功，请登录您的邮箱获取验证码");
            }
            request.getSession().setAttribute("reg_username", userEmail);//添加注册邮箱(用户名)与验证码绑定
            request.getSession().setAttribute("mailCode", codeNumber);
            request.getSession().setAttribute("sendTime", sendTime);
            //			} else {
            //				msg = new ResultMsg("F", "验证码已发送成功，请登录您的邮箱获取验证码");
            //			}
        }
        return msg;
    }

    /**
     * 根据手机号找回密码-提交
     *
     * @param request
     * @param response
     */
    @RequestMapping(value = "findPwdByMobile", method = "post")
    protected Object findPwdByMobile(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Map<String, Object> result = new HashMap<String, Object>();
        Map<String, String> params = this.getParameterMap(request);
        //校验验证码是否正确
        //是否开通短信校验
        String randCheck = ToolsUtil.getInstance().getValueByKey("randCheck");
        if (randCheck.equals("Y")) {
            //校验短信验证码
            ResultMsg msg = checkSmsCode(request, params);
            if (msg != null && msg.getFlag().equals("F")) {
                gotoErrorPage(request, response, msg.getMsg());
                result.put("flag", msg.getFlag());
                result.put("msg", msg.getMsg());
                result.put("ids", null);
                return result;
            }
        }
        //修改操作
        params.put("doCode", "U0005");
        ResultMsg msg = (ResultMsg) plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        if (msg != null && msg.getFlag().equals("F")) {
            result.put("flag", msg.getFlag());
            result.put("msg", msg.getMsg());
            result.put("ids", null);
            return result;
        } else {
            result.put("flag", "T");
            result.put("msg", "");
            result.put("ids", null);
        }
        return result;
    }

    /**
     * 发送短信验证码 1-注册 2-找回密码
     *
     * @param request
     * @param response
     * @return
     */

//木交所老代码
//    @RequestMapping(value = "sendSmsCode", method = "post")
//    protected Object sendSmsCode(HttpServletRequest request, HttpServletResponse response)
//            throws IOException {
//        Map<String, Object> result = new HashMap<String, Object>();
//        result.put("flag", "F");
//        result.put("msg", "短信验证码发送失败");
//        result.put("ids", "");
//        Map<String, String> params = this.getParameterMap(request);
//        Map<String, Object> paramsv = new HashMap<String, Object>();
//        //是否发送短信
//        String randCheck = ToolsUtil.getInstance().getValueByKey("randCheck");
//        if (randCheck.equals("N")) {
//            result.put("flag", "T");
//            result.put("msg", "短信验证码发送成功");
//            result.put("ids", "");
//            return result;
//        }
//        /**
//         * 配置文件获取验证码类型
//         * 验证码类型 1:数字,2:字母,3:数字与字母
//         * 验证码长度
//         * 是否实时发送 1 是 2 否
//         * 默认验证码
//         */
//        String randCodeType = ToolsUtil.getInstance().getValueByKey("randCodeType");
//        String randLength = ToolsUtil.getInstance().getValueByKey("randLength");
//        String isSendNow = ToolsUtil.getInstance().getValueByKey("isSendNow");
//        String defaultRand = ToolsUtil.getInstance().getValueByKey("defaultRand");
//        //业务类型 1 注册 2 找回密码 3 会员管理-更换手机号
//        String type = request.getParameter("type");
//        String codeNumber = "";//验证码
//        if (isSendNow.equals("2")) {
//            codeNumber = defaultRand;
//        } else {
//            codeNumber = PortalPubFactory
//                    .getRandomStr(randCodeType, Integer.parseInt(randLength), 97);
//        }
//        String msgContent = "";
//        if (type.equals("1")) {
//            msgContent = "您的注册验证码为" + codeNumber + "。此验证码五分钟内有效。【北京木交中心】";
//        } else if (type.equals("2")) {
//            msgContent = "您正在找回密码，验证码为" + codeNumber + "。此验证码五分钟内有效。【北京木交中心】";
//        } else if (type.equals("3")) {
//            msgContent = "您正在更换绑定手机号，验证码为" + codeNumber + "。此验证码五分钟内有效。【北京木交中心】";
//        }
//        paramsv.put("isSendNow", isSendNow);//实时发送
//        //		paramsv.put("isSendNow", "2");//测试用 只存数据 ????需要改-----------------------------
//        paramsv.put("delStatus", "T");//已发送-存储用
//        paramsv.put("msgType", "mobile");//类型手机
//        paramsv.put("msgStatus", "2");//状态发送成功
//        paramsv.put("msgLevel", "1");//级别
//        paramsv.put("msgPassNum", "1");//发送次数
//        if (type.equals("1")) {
//            paramsv.put("toUserMobile", params.get("member.mobile"));//接收手机号
//        } else if (type.equals("2")) {
//            paramsv.put("toUserMobile", params.get("frm_findpass_login_mobile"));//接收手机号
//        }
//        paramsv.put("msgContent", msgContent);
//        System.out.println("--------" + codeNumber);
//        ResultEntity entity = sendMsgByRpc(paramsv);
//        //发送成功 session存入验证码和当前时间
//        if (!Validator.isEmpty(entity) && entity.getResult().equals("T")) {
//            //验证码存入session
//            request.getSession().setAttribute("smsCode", codeNumber);
//            long nowTime = System.currentTimeMillis();//系统当前时间
//            request.getSession().setAttribute("sendTime", nowTime);
//        }
//        result.put("flag", String.valueOf(entity.getResult()));
//        result.put("msg", String.valueOf(entity.getMessage()));
//        result.put("ids", entity.getEntity());
//        return result;
//    }

    @RequestMapping(value = "sendSmsCode", method = "get")
    protected Object sendSmsCode(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("flag", "F");
        result.put("msg", "短信验证码发送失败");
        Map<String, String> params = this.getParameterMap(request);

        //读取配置文件是否开启发送短信验证码了
        String sms_code_start = ToolsUtil.getInstance().getLocalByKey("config.properties", "sms_code_start");

        /**
         * 配置文件获取验证码类型
         * 验证码类型 1:数字,2:字母,3:数字与字母
         * 验证码长度
         */
        String randCodeType = Validator.getDefaultStr(ToolsUtil.getInstance().getValueByKey("randCodeType"),"1");
        String randLength = Validator.getDefaultStr(ToolsUtil.getInstance().getValueByKey("randLength"),"6");
        //业务类型 1 注册 2 找回密码 3 更换手机号
        String type = Validator.getDefaultStr(request.getParameter("type"),"1");
        String codeNo =PortalPubFactory
                .getRandomStr(randCodeType, Integer.parseInt(randLength), 97);//验证码


        String userEname = params.get("uctUser.userEname");
        String mobile = params.get("uctUser.mobile");
        if(Validator.isNull(mobile)){
            result.put("flag", "F");
            result.put("msg", "手机号不能为空！");
        }
        log.info("["+userEname+"]注册申请，开始发送手机短信验证码...");
        log.info("手机号："+mobile);
        log.info("验证码："+codeNo);
        log.info("config内是否开启发送短信sms_code_start："+sms_code_start);
        if ("T".equals(sms_code_start)) {//开启发邮件才真正发送
            Map<String,String>  sendSmsResponse = SmsUtil.sendSms(mobile,codeNo);
            String requestId = sendSmsResponse.get("requestId");
            String code = sendSmsResponse.get("code");
            String bizId = sendSmsResponse.get("bizId");
            String message = sendSmsResponse.get("message");
            log.info("短信验证码发送返回结果：requestId="+requestId+",bizId="+bizId+",message="+message);
            if(Validator.isNotNull(bizId)&&"OK".equals(code)){
                BaseOsCache oscache = OsCacheOtherManager.getInstance()
                        .getBaseOsCache("mobile_obj_", 300);
                oscache.put(mobile,codeNo);
                result.put("flag", "T");
                result.put("msg", "短信验证码已发送至您手机！");
            }
        }else{
            BaseOsCache oscache = OsCacheOtherManager.getInstance()
                    .getBaseOsCache("mobile_obj_", 300);
            oscache.put(mobile,codeNo);
            result.put("flag", "T");
            result.put("msg", "平台暂停发送短信，本次验证码为: "+codeNo);
        }

//        System.out.println("短信接口返回的数据----------------");
//        System.out.println("Code=" + sendSmsResponse.getCode());
//        System.out.println("Message=" + sendSmsResponse.getMessage());
//        System.out.println("RequestId=" + sendSmsResponse.getRequestId());
//        System.out.println("BizId=" + sendSmsResponse.getBizId());
        return result;
    }

    /**
     * description:  用户注册(短信注册)
     * 使用页面：user-reg.jsp
     */
    @RequestMapping(value = "userReg", method = "post")
    protected Object userReg(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "dymicSql");
        params.put("resultType", "processSql");
        if (StrUtil.isNotNull(params.get("uctUser.userEname"))) {
            params.put("loginUser_userEname", params.get("uctUser.userEname"));//确保其他表中没有该字段
        }
        Map<String, Object> result = new HashMap<String, Object>();
        ResultMsg msg = checkSmsCode(request, params);
        if ((msg != null) && (msg.getFlag().equals("F"))) {
            result.put("flag", msg.getFlag());
            result.put("msg", msg.getMsg());
            result.put("ids", null);
            return result;
        }
        params = AdapterFactory.getInstance()
                .getReqParamForBefor("setReqParam,createInfo", params, request, response);//前拦截
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);
        result.put("flag", String.valueOf(entity.getResult()));
        result.put("msg", String.valueOf(entity.getMessage()));
        result.put("ids", entity.getEntity());
        return result;
    }


    /**
     * description: 校验短信验证码。同时根据用户名和手机号判断是否存在该用户
     */
    @RequestMapping(value = "checkMsgCode", method = "post")
    protected Object checkMsgCode(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        //校验验证码
        ResultMsg msg = new ResultMsg();

        //判断是否存在该用户。

    if(Validator.isNull(params.get("uctUser.userEname"))||Validator.isNull(params.get("uctUser.mobile"))){
        throw  new BusinessException("用户名和手机号不能为空！");
    }
        params.put("doCode", "dymicSql");
        params.put("modelTypes", "s_uctUser");
        params.put("resultType", StrUtil.doNull(request.getParameter("resultType"), "objInfo"));
        params.put("resultObjType", "obj");
        ResultEntity entity = (ResultEntity) netPlugin.doInvoke(request, response,
                params);
        if (!ToolsUtil.isEmpty(entity.getEntity())) {
//            DataMap<String> dataMap  =(DataMap<String>) entity.getEntity();
//            String userEname =dataMap.get("userEname");
            msg = checkSmsCode(request, params);//校验短信验证码
        }else{
            msg.setMsg("没有找到此用户或者用户名和手机不匹配！");
            msg.setFlag("F");
        }
        return msg;
    }

    @RequestMapping(value = "editPasswd", method = "post")
    protected Object editPasswd(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = getParameterMap(request);
        params.put("doCode", "U0005");
        ResultMsg msg = (ResultMsg) plugin.doInvoke(request, response,
                params);
        return msg;
    }

    /**
     * 进行RPC接口注册的 IP/地址 和 端口的配置定义
     *
     * @return
     */
    private InterfaceRegister getInterfaceRegisterByMsg() {
        String urlKey = "msg_server_url";
        String portKey = "msg_server_port";
        String urlSubfix = "/send/service/doService.action";
        InterfaceRegister register = new InterfaceRegister();
        String reqUrl = ConfigUtil.getInstance().getValueByKey(urlKey);
        String infoUrl = reqUrl + urlSubfix;
        if (reqUrl.startsWith("https:")) {
            register.setCallType("https");
            register.setAddress(infoUrl);
        } else if (reqUrl.startsWith("http:")) {
            register.setCallType("http");
            register.setAddress(infoUrl);
        } else {
            String port = ConfigUtil.getInstance().getValueByKey(portKey);
            register.setAddress(reqUrl);
            register.setPort(port);
            register.setCallType("socket");
        }
        return register;
    }

    /**
     * description:  验证短信验证码
     */
    private ResultMsg checkSmsCode(HttpServletRequest request, Map<String, String> params) {
        ResultMsg msg = new ResultMsg("T", "验证码验证通过");
        String mobile = params.get("uctUser.mobile");
        BaseOsCache oscache = OsCacheOtherManager.getInstance()
                .getBaseOsCache("mobile_obj_", 300);
        String smsCode = String.valueOf(oscache.get(mobile));
        if (ToolsUtil.isNull(smsCode)) {
            msg = new ResultMsg("F", "请先发送验证码");
            return msg;
        }
        if ((StrUtil.isNull(params.get("rand")))) {
            msg = new ResultMsg("F", "验证码不能为空");
            return msg;
        }

        if (!params.get("rand").equals(smsCode)) {
            msg = new ResultMsg("F", "验证码错误");
            return msg;
        }
        //验证码验证通过后删除session验证码
        oscache.remove(mobile);
        return msg;
    }


//    private ResultMsg checkSmsCode(HttpServletRequest request, Map<String, String> params) {
//        ResultMsg msg = new ResultMsg("T", "验证码验证通过");
//        String ifSmsCode = request.getParameter("smsCodeMark");
//        if (ToolsUtil.isNotNull(ifSmsCode))
//            return null;
//        String smsCode = String.valueOf(request.getSession().getAttribute("smsCode"));
//        if (ToolsUtil.isNull(smsCode)) {
//            msg = new ResultMsg("F", "请先发送验证码");
//            return msg;
//        }
//        if ((StrUtil.isNull(params.get("rand")))) {
//            msg = new ResultMsg("F", "验证码不能为空");
//            return msg;
//        }
//        //检验时间是否过期randCodeTime
//        String randCodeTime = ToolsUtil.getInstance().getValueByKey("randCodeTime");//短信验证码过期时间
//        String sendTime = String.valueOf(request.getSession().getAttribute("sendTime"));//验证码生成时间
//        long rCount = Long.valueOf(randCodeTime);//短信验证码过期时间
//        long sCount = Long.valueOf(sendTime);//验证码生成时间
//        long nowTime = System.currentTimeMillis();//系统当前时间
//        if (nowTime - sCount > rCount) {
//            msg = new ResultMsg("F", "验证码已失效，请重新发送");
//            //删除session验证码
//            request.getSession().removeAttribute("smsCode");
//            request.getSession().removeAttribute("sendTime");
//            return msg;
//        }
//        if (!params.get("rand").equals(smsCode)) {
//            msg = new ResultMsg("F", "验证码错误");
//            return msg;
//        }
//        //验证码验证通过后删除session验证码
//        request.getSession().removeAttribute("smsCode");
//        request.getSession().removeAttribute("sendTime");
//        return msg;
//    }


    /**
     * description:  用户新增
     */
    @RequestMapping(value = "saveUser", method = "post")
    protected Object adminEditUser(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        ResultMsg msg = new ResultMsg("F", "操作失败");
        Map<String, String> params = this.getParameterMap(request);
        msg = (ResultMsg) plugin.doInvoke(request, response,
                params);// PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        return msg;
    }

    /**
     * description:  用户删除
     */
    @RequestMapping(value = "delUser", method = "post")
    protected Object adminSaveUser(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        ResultMsg msg = new ResultMsg("F", "操作失败");
        Map<String, String> params = this.getParameterMap(request);
        msg = (ResultMsg) plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        return msg;
    }

    /**
     * description:  拥有的角色
     */
    @RequestMapping(value = "userRoleData", method = "post")
    protected Object userRoleData(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        return plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
    }

    /**
     * description:  分配角色给用户
     */
    @RequestMapping(value = "roleToUser", method = "post")
    protected Object roleToUser(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        return plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
    }

    /**
     * description:  继承自角色的权限
     */
    @RequestMapping(value = "userRightRoleData", method = "post")
    protected Object userRightRoleData(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        return plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
    }

    /**
     * description:  数据权限机构
     */
    @RequestMapping(value = "userRightOrgData", method = "post")
    protected void userRightOrgData(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        Object obj = plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        JSONArray jary = JSONArray.fromObject(obj);
        this.outputJson(jary.toString(), response, request.getParameter("callback"));
    }

    /**
     * description:  数据权限机构
     */
    @RequestMapping(value = "roleActData", method = "post")
    protected void roleActData(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        Object obj = plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        JSONArray jary = JSONArray.fromObject(obj);
        this.outputJson(jary.toString(), response, request.getParameter("callback"));
    }

    /**
     * description:
     */
    @RequestMapping(value = "userDataGive", method = "post")
    protected Object userDataGive(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        ResultMsg resultMsg = (ResultMsg) plugin.doInvoke(request, response,params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);

        //20180806 在未重新登录的情况下，追加新加入的机构权限到loginUer中
        /**
        String giveType = params.get("giveType");
        if("org".equals(giveType)){
            String newOrgId = params.get("objId");
            if(resultMsg.getFlag()=="T"){
                LoginUser loginUser = PortalPubFactory.getInstance().getLoginUser(request);
                if (loginUser != null) {
                    String oldOrgIds = loginUser.getDataOrgIds();
                    if(!StrUtil.isNull(oldOrgIds) && oldOrgIds.length()>0){
                        if(!oldOrgIds.endsWith(",")){
                            oldOrgIds+=",";
                        }
                        oldOrgIds+=newOrgId;
                        loginUser.setDataOrgIds(oldOrgIds);
                    }
                }
                request.getSession().setAttribute("loginUser", loginUser);
            }
        }**/
        return resultMsg;
    }

    /**
     * description:  全部权限
     */
    @RequestMapping(value = "userRightAll", method = "post")
    protected Object userRightAll(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        return plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
    }

    /**
     * description:  分配数据权限给用户
     */
    @RequestMapping(value = "userRightAct", method = "post")
    protected void userRightAct(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        Object obj = plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        JSONArray jary = JSONArray.fromObject(obj);
        this.outputJson(jary.toString(), response, request.getParameter("callback"));
    }

    /**
     * description:  执行权限值分配
     */
    @RequestMapping(value = "authorizeAct", method = "post")
    protected Object authorizeAct(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        return plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
    }

    /**
     * description:  数据权限部门
     */
    @RequestMapping(value = "userRightDeptData", method = "post")
    protected void userRightDeptData(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        Object obj = plugin.doInvoke(request, response,
                params);//PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
        JSONArray jary = JSONArray.fromObject(obj);
        this.outputJson(jary.toString(), response, request.getParameter("callback"));
    }

    /**
     * 复制rpc的t_config指定文件
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "configCopy", method = "get")
    protected void configCopy(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        Map<String, String> params = this.getParameterMap(request);
        log.info("configCopy.params"+params);
        String fileName = String.valueOf(params.get("fileName"));
        String newFileName = String.valueOf(params.get("newFileName"));
        if(StrUtil.isNull(fileName)||StrUtil.isNull(newFileName)){
            ResultMsg msg = new ResultMsg("F", "缺失参数");
            this.outputJson(msg.toString(), response, request.getParameter("callback"));
        }else{
            ResultMsg msg = new ResultMsg("F", "操作失败");
            Object obj = plugin.doInvoke(request, response, params);
            if(obj!=null){
                ResultEntity resd = (ResultEntity)obj;
                if("true".equals(resd.getResult()) && resd.getEntity()!=null){
                    msg = new ResultMsg("T", String.valueOf(resd.getEntity()));
                }else{
                    msg = new ResultMsg("F", resd.getMessage());
                }
            }
            this.outputJson(msg.toString(), response, request.getParameter("callback"));
        }
    }

    /**
     * description:  验证验证码
     */
    private ResultMsg checkRandCode(HttpServletRequest request, Map<String, String> params) {
        ResultMsg msg = null;
        String ifRandCode = request.getParameter("randCodeMark");
        if (ToolsUtil.isNotNull(ifRandCode))
            return null;
        log.info("getSession-------->>>"+request.getSession().getAttribute("randCode"));
        String randCode = StrUtil.doNull(request.getHeader("rand-code"),String.valueOf(request.getSession().getAttribute("randCode")));
        log.info("randCode--->>"+randCode);

        if (ToolsUtil.isNull(randCode)) {
            msg = new ResultMsg("F", "验证码已失效");
            return msg;
        }
        if ((StrUtil.isNull(params.get("rand")))) {
            msg = new ResultMsg("F", "验证码不能为空");
            return msg;
        }
        if (!params.get("rand").equals(randCode)) {
            msg = new ResultMsg("F", "验证码错误");
            return msg;
        }
        return msg;
    }

    /**
     * description:  验证验证码
     */
    private ResultMsg checkEmailCode(HttpServletRequest request, Map<String, String> params) {
        ResultMsg msg = new ResultMsg("T", "验证成功");
        if ((StrUtil.isNull(params.get("emailCode")))) {
            msg = new ResultMsg("F", "验证码不能为空");
            return msg;
        }
        String randCode = String.valueOf(request.getSession().getAttribute("mailCode"));
        if (!params.get("emailCode").equals(randCode)) {
            msg = new ResultMsg("F", "验证码错误");
            return msg;
        }
        String o_email = (String) request.getSession().getAttribute("reg_username");
        String n_email = params.get("username");
        if (!o_email.equals(n_email)) {
            msg = new ResultMsg("F", "验证码错误");
            return msg;
        }
        return msg;
    }

    /**
     * description:  邮箱链接验证
     */
    private void setUserPwd(HttpServletRequest request, HttpServletResponse response,
            Map<String, String> params) throws ServletException, IOException {
        if (ToolsUtil.isNull(params.get("rand"))) {
            response.sendRedirect(request.getContextPath());
            return;
        }
        long toDay = System.currentTimeMillis();
        String encryKey = params.get("rand");//发送时间
        long randL = Long.valueOf(encryKey);
        long cha = toDay - randL;
        if (cha <= 24 * 3600 * 1000L && cha > 0) {
            String email1 = TeaUtil.decryptByTea(
                    params.get("e"));//DesUtils.getInstance().decrypt(params.get("e"));
            String userEname = TeaUtil.decryptByTea(
                    params.get("u"));//DesUtils.getInstance().decrypt(params.get("u"));
            request.setAttribute("userEname", userEname);
            request.setAttribute("userEmail", email1);
        } else {
            gotoErrorPage(request, response, "邮箱验证链接已失效");
            return;
        }
        request.getRequestDispatcher("/doSendPage?toPage=res002").forward(request, response);
    }

    /**
     * description:  登录成功后跳转页面
     */
    private void gotoIndex(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String path = request.getContextPath();
        String csetUrl = request.getScheme() + "://" + request.getServerName() + ":" + request
                .getServerPort() + path;
        //要跳转到哪个url
        String gotoURL = request.getParameter("go");
        if (StrUtil.isNull(gotoURL)) {
            gotoURL = csetUrl;
        } else {
            if (!gotoURL.startsWith("http")) {
                gotoURL = request.getScheme() + "://" + request.getServerName() + ":" + request
                        .getServerPort() + gotoURL;
            }
        }
        //自定义登录页面
        String login_url = ToolsUtil.getInstance().getValueByKey("uct_server");
        //获取系统名称
        String tokenId = String.valueOf(request.getSession().getAttribute("tokenId"));
        String reqParams = "";
        if ("T".equals(ToolsUtil.getInstance().getValueByKey("is_url_params"))) {
            reqParams = PassportHelper.getInstance().getReqParams(request, "doCode,go");
            reqParams = PassportHelper.getInstance().isNov(reqParams, reqParams, "?" + reqParams);
        }
        ArrayList<String> lst = new ArrayList<String>();
        StringBuffer tokenUrl = new StringBuffer();
        lst.add(login_url);
        lst.add(tokenId);
        lst.add(gotoURL + reqParams);
        lst.add("apache");
        lst.add(csetUrl);
        Collections.sort(lst);
        String sha1Rtn = PassportHelper.getInstance().SHA1(lst);
        //是否使用统一登录系统登录 T/F
        String login_pass = ToolsUtil.getInstance().getValueByKey("login.pass");
        if ("T".equals(login_pass)) {
            //如果cookie为空,则跳转到登录页面
            tokenUrl.append(login_url);
            tokenUrl.append("?");
            tokenUrl.append("ptlang=" + sha1Rtn);
            tokenUrl.append("&");
            tokenUrl.append("tokenId=" + tokenId);//设置远程cookie
            tokenUrl.append("&");
            tokenUrl.append("go=" + gotoURL + reqParams);
            tokenUrl.append("&");
            tokenUrl.append("cset=" + csetUrl);
        } else {
            tokenUrl.append(login_url);
        }
        response.sendRedirect(tokenUrl.toString());
    }

    private void setLoginUser(HttpServletRequest request) {
        LoginUser loginUser = PBOSSOTools.getLoginUser(request);
        if (null == loginUser) {
            try {
                String cookieValue = PassportHelper.getInstance().getCurrCookie(request);
                String value = PassportHelper.getInstance().getCurrCookie(request, "_uc.sso");
                if (StrUtil.isNotNull(cookieValue) && StrUtil.isNotNull(value)) {
                    //value = DesUtils.getInstance().decrypt(value);
                    loginUser = PBOSSOTools.getLoginUserFromUserCenterSso(cookieValue);
                    if (null != loginUser) {
                        request.getSession().setAttribute("loginUser", loginUser);
                    }
                }
            } catch (Exception e) {
            }
        }
    }

    /**
     * 校验用户是否存在
     * @param request
     * @param response
     * @return
     */
    //	@RequestMapping(value = "checkUserInfo", method = "get")
    //	protected Object checkUserInfo(HttpServletRequest request, HttpServletResponse response)throws IOException {
    //		Map<String, String> params = getParameterMap(request);
    //		Map<String, Object> result = new HashMap<String, Object>();
    //		result.put("flag", "T");
    //		request.setAttribute("doCode", params.get("doCode"));
    //		request.setAttribute("userEname", params.get("userEname"));
    //		Object userObj = PortalPubFactory.getInstance().getPlugin("uct").doInvoke(request, response, params);
    //		System.out.println("---"+userObj);
    //		if(!StrUtil.isEmpty(userObj)){
    //			result.put("flag", "F");
    //			result.put("msg", "登录名已存在");
    //			result.put("ids", null);
    //			return result;
    //		}
    //		return null;
    //	}

}
